<template>
    <h2>我的优惠券</h2>
    <table border="1">
      <thead>
        <tr>
            <td>用户编号</td>
            <td>真实名称</td>
            <td>折扣券标签</td>
            <td>折扣券状态</td>
            <td>操作</td>
        </tr>
      </thead>
      <tbody>
        <tr v-for="item in info" :key="item.ML_Id">
            <td>{{item.ML_Id}}</td>
            <td>{{item.MI_Name}}</td>
            <td>{{item.Discount_Title}}</td>
            <td>{{item.WDC_State==false?"未使用":"已使用"}}</td>
            <td>       
                <a herf="#"  @click="ChangeState(item.WDC_Id)">核销</a>
            </td>
        </tr>
      </tbody>
    </table>
</template>

<script setup lang="ts">
import{ref,onMounted} from 'vue'
import axios from 'axios'
const params=new URLSearchParams(location.search);
const ML_Id=params.get('ML_Id');

const ChangeState=(WDC_Id:number)=>{
  alert(WDC_Id);
    axios.get('https://localhost:44320/api/Discount/ChaneState',{
      params:{
        WDC_Id:WDC_Id
      }
    })
    .then(res=>{
      console.log(res.data);
      if(res.data>0)
      {
        alert('核销成功');
        loadData();
      }
      else{
        alert('核销失败');
      }
    })
}


const info=ref([{
    "ML_Id": "b25c25a0-04e0-461e-b150-b7abf2e812b4",
    "MI_Name": "",
    "WDC_State": false,
    "WDC_Id": 1,
    "Discount_Title": ""
  }] )

onMounted(()=>{
  loadData();
})
const loadData=()=>{
  axios.get('https://localhost:44320/api/Discount/ShowMemberDdiscountInfo',{
    params:{
        ML_Id:ML_Id
    }
   })
   .then(res=>{
    console.log(res.data);
       info.value=res.data;
   })
    
}
</script>